import { defineStore } from "pinia";
import { getRemainList } from "../api/appointment.api";
import dayjs from "dayjs";
import type { RemainListRes } from "types/appointment.type";

interface AppointmentStoreState {
  remainData: Record<string, RemainListRes[]>;
}

export const useAppointmentStore = defineStore("appointmentStore", {
  state: (): AppointmentStoreState => {
    return {
      remainData: {},
    };
  },
  actions: {
    // 获取诊所余号列表
    async getRemainListApi(params: { deptId: number; time: number }) {
      const date = dayjs(params.time).format("YYYY-MM-DD");

      const res = await getRemainList({
        deptId: params.deptId,
        visitDate: date,
      });

      if (res.code === "200") {
        this.remainData[date] = res.data ?? [];
      }
    },
  },
});
